import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import ViewLayout from '../layout/ViewLayout.vue'

Vue.use(VueRouter)

export const routes = [
  {
    path: '/',
    name: 'Home',
    component: ViewLayout,
    meta: {
      title: '企业管理',
      icon: 'fund',
    },
    children: [
      {
        path: 'home',
        component: Home,
        meta: {
          title: '企业审核'
        },
      },
    ]
  },
  {
    path: '/home1',
    component: Home,
    meta: {
      title: '反馈管理',
      icon: 'interaction',
    }
  },
  {
    path: '/home2',
    component: Home,
    meta: {
      title: '敏感词库管理',
      icon: 'shake',
    }
  },
  {
    path: '/home3',
    component: () => import(/* webpackChunkName: "about" */ '../views/About.vue'),
    meta: {
      title: '用户管理',
      icon: 'user',
    }
  },
]

const singleRoute = [
  {
    path: '/login',
    name: 'login',
    meta: {
      title: '登录'
    },
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
  }
]

// 所有的标记single的页面不会被manage管理后台潜逃
setSingle(singleRoute)
function setSingle(routes) {
  routes.forEach(element => {
    element.meta.single = true
    if (element.children) {
      setSingle(element.children)
    }
  });
}

const globalRoutes = [...routes, ...singleRoute]

// 路由所有子集可以获取父级对象，递归设置
setParentTree(globalRoutes)
function setParentTree(routes, parent) {
  routes.forEach(item => {
    item.meta.parent = parent
    if (item.children) {
      setParentTree(item.children, item)
    }
  })
}


const router = new VueRouter({
  routes: globalRoutes
})

export default router
